package com.atguigu.yygh.commom.utils;

import com.atguigu.yygh.commom.helper.JwtHelper;

import javax.servlet.http.HttpServletRequest;

/**
 * @author mengWu
 * @Date 2021年05月27日 15:22
 * 获取当前用户的信息
 */

public class AuthContextHolder {
    //获取当前用户的id
    public static long getUserId(HttpServletRequest request){
        //从header中获取token
        String token = request.getHeader("token");
        //jwt从token中获取userid
        Long userId = JwtHelper.getUserId(token);
        //返回结果
        return userId;
    }
    //获取当前用户的名称
    public static String getUserName(HttpServletRequest request){
        //从header中获取token
        String token = request.getHeader("token");
        //jwt从token中获取userName
        String userName = JwtHelper.getUserName(token);
        //返回结果
        return userName;
    }


}
